home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / bbs / aselect.zip / MSELECT.MEX < prev    next >
Text File  |  1996-05-25  |  12KB  |  430 lines

  1. // ----------------------------------------------------------------------
  2. //
  3. //  Area Selector v0.1 beta
  4. //
  5. //  Copyright 1996 by Brian C. Lane
  6. //
  7. //  All Rights Reserver
  8. //  This code may not be modified and used in any other piece of code
  9. //  without acknowledging the source (me!)
  10. //
  11. //-----------------------------------------------------------------------
  12. //
  13. //  This code is a work in progress. It currently is only useful on the
  14. //  message bases, the next version will also work on file bases.
  15. //
  16. //  Probably the only thing you will want to change are the colors,
  17. //  defined directly below as GC_*, see MAX.DOC for info on how to set
  18. //  the AVATAR colors.
  19. //
  20. //  ---------------------------------------------------------------------
  21. //  INSTALL:
  22. //    You've obviously unpacked the archive, so put mselect.mex and
  23. //    xgetch.mh in your /max/m subdirectory. Run MEX on it:
  24. //      MEX mselect
  25. //
  26. //    Change your Message Area change command to look like so:
  27. //      MEX     M/mselect               Demoted "Area change"
  28. //
  29. //    Don't forget to comment out the old Area change line.
  30. //    Now when your users select 'A'rea change from the message menu
  31. //    they will be presented with a user friendly interface!
  32. //
  33. //  ---------------------------------------------------------------------
  34. //
  35. //  This allows a user to walk up and down the areas available on the
  36. //  system and to select one to read by hitting enter. It checks the
  37. //  user's video type and uses the default(ugly) message selection if
  38. //  ANSI isn't supported.
  39. //
  40. // ----------------------------------------------------------------------
  41.  
  42. #include <max.mh>
  43. #include <prm.mh>
  44. #include <xgetch.mh>                    // Use xgetch routine
  45.  
  46.  
  47. // ----------------------------------------------------------------------
  48. // Color definitions
  49. // ----------------------------------------------------------------------
  50. #define GC_TITLE_BBS    "\x16\x01\x79"
  51. #define GC_TITLE_USER   "\x16\x01\x7e"
  52. #define GC_HELP         COL_GRAY
  53. #define GC_NUM          COL_WHITE
  54. #define GC_UNREAD       COL_LGREEN
  55. #define GC_NAME         COL_WHITE
  56. #define GC_DESC         COL_LBLUE
  57. #define GC_NUM_HI       "\x16\x01\x78"
  58. #define GC_UNREAD_HI    "\x16\x01\x7A"
  59. #define GC_NAME_HI      "\x16\x01\x78"
  60. #define GC_DESC_HI      "\x16\x01\x79"
  61.  
  62.  
  63. #define ATYPE msg
  64. #define AREAT _marea
  65. #define ARVAR marea
  66. #define AreaFindFirst msgareafindfirst
  67. #define AreaFindNext  msgareafindnext
  68. #define AreaFindPrev  msgareafindprev
  69. #define AreaFindClose msgareafindclose
  70. #define AreaSelect    msgareaselect
  71.  
  72.  
  73. //========================= Page structure =================================
  74. // Lastfile: This integer defines the last file on this page, in most cases
  75. //           this should equal to 16, except for the last page
  76. // Filename: Contains the filename, BUT!  if filename="", <desc> contains
  77. //           a description that is continued from the last file.
  78. //           And, if filename="z", <desc> is a comment.
  79. // Size: Size of the file
  80. // Date: Date of file as a string
  81. // Desc: Description or comment
  82. // Tagged: TRUE if file is tagged and FALSE if not
  83. struct _page
  84. {
  85.   string: name;
  86.   long: num;
  87.   long: current;
  88.   long: high;
  89.   string: desc;
  90.   int: tagged;
  91. } ;
  92. array [1..20] of struct _page: page;
  93. int:    lastgroup;                      // Lastgroup on the page
  94. int:    pos;                            // Position 1..18
  95. int:    errwin;                         // Indicates if line 25 needs clearing
  96. string: last;                           // Last area selected by the user
  97.  
  98.  
  99. // --------------------------------------------------------------------
  100. // Fill in the page structure with the next 18 groups, starting with
  101. // The next group after the one in page[18].name, unless it is null,
  102. // then start with the top
  103. // --------------------------------------------------------------------
  104. int next_group_page()
  105. {
  106.   int:                  i, x;
  107.   struct AREAT:         a;
  108.  
  109.  
  110.   if ( lastgroup = 0 )
  111.   {
  112.     i:=AreaFindFirst(a, "", AFFO_NODIV);
  113.     if( i = 0 )
  114.     {
  115.       return -1;
  116.     }
  117.   } else {
  118.     i:=AreaFindFirst(a, page[lastgroup].name, AFFO_NODIV);
  119.     if( i = 0 )
  120.     {
  121.       return -2;
  122.     }
  123.  
  124.     i:=AreaFindNext(a);
  125.     if( i = 0 )
  126.     {
  127.       return -3;
  128.     }
  129.   }
  130.  
  131.   print( AVATAR_GOTO, (char)25, (char)1);
  132.   print( COL_WHITE, "Scanning group ");
  133.  
  134.   x := 1;
  135.   while( ( x < 19 ) and i )
  136.   {
  137.     print( AVATAR_GOTO, (char)25, (char)16 );
  138.     print( x );
  139.  
  140.     i := AreaSelect( a.name );
  141.     page[x].name := a.name;
  142.     page[x].desc := substr( a.descript, 1, 40);
  143.     page[x].num := ATYPE.num;
  144.     page[x].current := ATYPE.current;
  145.     page[x].high := ATYPE.high;
  146.  
  147.     i:=AreaFindFirst(a, a.name, AFFO_NODIV);
  148.     i:=AreaFindNext(a);
  149.  
  150.     if( i )
  151.       x := x + 1;
  152.   }
  153.   AreaFindClose();
  154.  
  155.   if ( i )
  156.     lastgroup := x-1;
  157.   else
  158.     lastgroup := x;
  159. }
  160.  
  161.  
  162. // ----------------------------------------------------------------------
  163. // Fill in the page structure with the previous 18 groups, starting with
  164. // The previous group before the one in page[1].name, unless it is null,
  165. // then don't do anything.
  166. // ----------------------------------------------------------------------
  167. int prev_group_page()
  168. {
  169.   int:                  i, x;
  170.   struct AREAT:        a;
  171.  
  172.  
  173.   i:=AreaFindFirst(a, page[1].name, AFFO_NODIV);
  174.   if( i = 0 )
  175.   {
  176.     return -1;
  177.   }
  178.  
  179.   i:=AreaFindPrev(a);
  180.   if( i = 0 )
  181.   {
  182.     return -2;
  183.   }
  184.  
  185.  
  186.   print( AVATAR_GOTO, (char)25, (char)1);
  187.   print( COL_WHITE, "Scanning group ");
  188.  
  189.   x := 18;
  190.   while( ( x > 0 ) and i )
  191.   {
  192.     print( AVATAR_GOTO, (char)25, (char)16 );
  193.     print( strpadleft( itostr( x ), 2, ' ') );
  194.  
  195.     i := AreaSelect( a.name );
  196.     page[x].name := a.name;
  197.     page[x].desc := substr( a.descript, 1, 40);
  198.     page[x].num := ATYPE.num;
  199.     page[x].current := ATYPE.current;
  200.     page[x].high := ATYPE.high;
  201.  
  202.     i:=AreaFindFirst(a, a.name, AFFO_NODIV);
  203.     i:=AreaFindPrev(a);
  204.  
  205.     if( i )
  206.       x := x - 1;
  207.   }
  208.   AreaFindClose();
  209.  
  210.   lastgroup := 18;
  211. }
  212.  
  213.  
  214.  
  215.  
  216. // ----------------------------------------------------------------------
  217. // Update the display with the current page information
  218. //
  219. // Shows the title bar with the BBS name and ??
  220. // Shows the help bar at the bottom of the screen
  221. //
  222. // Shows 18 groups in format:
  223. //   #   [unread msgs]   name     description
  224. //
  225. // ----------------------------------------------------------------------
  226. int show_group_page()
  227. {
  228.   int:  x;
  229.   int:  unread;
  230.  
  231.   print( AVATAR_CLS );
  232.  
  233.   print( GC_TITLE_BBS, "  ", strpad( prm_string(PRM_SYSNAME), 38, ' ' ), GC_TITLE_USER, strpadleft( usr.name, 38, ' ' ), "  " );
  234.  
  235.   for( x := 1; x <= lastgroup; x := x + 1 )
  236.   {
  237.     print( AVATAR_GOTO, (char)(x+2), (char)2 );
  238.     unread := page[x].high - page[x].current;
  239.     print( GC_NUM, strpadleft( itostr(x), 3, ' '), GC_UNREAD, strpadleft( itostr(unread), 3, ' '), "  ", GC_NAME, strpad( page[x].name, 30, ' '), GC_DESC, page[x].desc);
  240.   }
  241.  
  242.   print( AVATAR_GOTO, (char)22, (char)12 );
  243.   print( GC_HELP, "[arrows] = select       [enter] = read       [Q] = Quit" );
  244.  
  245.   // Return cursor to an out of the way place
  246.   print( AVATAR_GOTO, (char)1, (char)1 );
  247.  
  248.   return 0;
  249. }
  250.  
  251.  
  252.  
  253. // --------------------------------------------------------------------
  254. // Hilight one line in the list of groups
  255. // --------------------------------------------------------------------
  256. int hilight_group( int: x )
  257. {
  258.   int:  unread;
  259.  
  260.   print( AVATAR_GOTO, (char)(x+2), (char)1 );
  261.   unread := page[x].high - page[x].current;
  262.   print( GC_NUM_HI, " ", strpadleft( itostr(x), 3, ' '), GC_UNREAD_HI, strpadleft( itostr(unread), 3, ' '), "  ", GC_NAME_HI, strpad( page[x].name, 30, ' '), GC_DESC_HI, strpad( page[x].desc, 41, ' ') );
  263.   print( AVATAR_GOTO, (char)(x+2), (char)1 );
  264. }
  265.  
  266.  
  267. // --------------------------------------------------------------------
  268. // Un-Hilight one line in the list of groups
  269. // --------------------------------------------------------------------
  270. int unhilight_group( int: x )
  271. {
  272.   int:  unread;
  273.  
  274.   print( AVATAR_GOTO, (char)(x+2),